String.prototype.format = function (args)
{
    if (arguments.length == 0) return this;

    var result = this;
    if (arguments.length == 1 && typeof (args) == "object")
        for (var key in args)
            result = result.replace(new RegExp("({" + key + "})", "g"), args[key]);
    else
        for (var i = 0; i < arguments.length; i++)
            if (arguments[i] == undefined)
                return "";
            else
                result = result.replace(new RegExp("({[" + i + "]})", "g"), arguments[i]);

    return result;
}